#include "GMWKeyDown.h"
#include "Factory.h"
#include "TimerMS.h"
#include "SendGameMessage.h"
#include "ServerManager.h"
#include "GMSetVel.h"

#include <iostream>

GMWKeyDown::GMWKeyDown()
{
	m_id = -1;
}

void GMWKeyDown::Execute()
{
	// called on server
	// send the set vel to client
	GMSetVel sv;
	sv.SetID(m_id);
	sv.SetVelZ(2.0f);
	sv.SetVelX(0.0f);
	sv.SetVelY(0.0f);
	TheServerManager::Instance()->SendGameMessageToAll(sv);

	//SendGameMessage(sv, &(TheServerManager::Instance()->GetClient(m_id)));
	std::cout << "set the player position: " << m_id << std::endl;

}

bool GMWKeyDown::Read(SocketMessage* sm)
{
	sm->ReadInt(&m_id);
	
	return true;
}

void GMWKeyDown::Write(SocketMessage* sm)
{
	sm->WriteString("GMWKeyDown");
	sm->WriteInt(m_id);
}

void GMWKeyDown::SetID(int i)
{
	m_id = i;
}

int GMWKeyDown::GetID() const
{
	return m_id;
}